package com.game.astar.main;

import java.awt.Point;
import java.util.List;
import java.util.Random;

import com.game.astar.AStar2;
import com.game.astar.util.MapUtil;

public class WayfindingMain 
{
	static Random random = new Random();
	/*地图宽*/
	static int width = 200;
	/*地图高*/
	static int height = 100;
	/*阻挡*/
	static int stop = 2000;
	
//	static int stop = 100;
	
	/*次数*/
	static int count = 1;
	
	public static void main(String[] args) 
	{	
		long time = System.currentTimeMillis();
		
		int startY = random.nextInt(height);
		int startX = random.nextInt(width);
		
		int endY = random.nextInt(height);
		int endX = random.nextInt(width);
		
		/*构造地图*/
		char[][] map = MapUtil.paintingRandomStopMap(height, width, stop, startX, startY, endX, endY);
		
		for (int i = 0; i < count; i++) 
		{
			search(startX, startY, endX, endY, map);
		}
		
		System.out.println("X:" + width + ", Y:" + height + ", 寻路次数:" + count + " , 搜索耗时:" + (System.currentTimeMillis() - time)  + " ms");
	}
	
	private static void search(int startX, int startY, int endX, int endY, char[][] map)
	{
		MapUtil.outputMap(map);
//		
//		System.out.println(" \t======================================");
		
		/*查找路径*/
//		boolean bool = new WayfindingDrive().searchPath(startX, startY, endX, endY, map);
//		boolean bool = new FindingHeapDrive(map).searchPath(startX, startY, endX, endY);
		AStar2 star = new AStar2(map, 3000);
		List<Point> list = star.find(startX, startY, endX, endY);
		
		System.out.println(list);

		
		/*if(bool)
		{
			输出结果
			MapUtil.outputMap(map);
			System.out.println("成功!");
		}
		else
		{
			System.out.println("没有找到路径!");
		}*/
	}
}
